package com.edu.servlet;

import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.edu.bean.Upkeep;
import com.edu.service.UpkeepService;
import com.edu.service.impl.UpkeepServiceImpl;
@WebServlet("/addupkeeps.do")
public class AddUpkeepServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		UpkeepService us = new UpkeepServiceImpl();
		String uid = req.getParameter("userid");
		String cid = req.getParameter("carid");
		String name = req.getParameter("upkeepname");
		String introduce = req.getParameter("introduce");
		String state = req.getParameter("state");
		String price = req.getParameter("price");
		String createdat = req.getParameter("createdat");
		String updatedat = req.getParameter("updatedat");
		int userid = Integer.parseInt(uid);
		int carid = Integer.parseInt(cid);
		double pr = Double.parseDouble(price);
		DateFormat dft = new SimpleDateFormat("yyyy-MM-dd");
		Date begin=null;
		Date update=null;
		try {
			begin = dft.parse(createdat);
			update =dft.parse(updatedat);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Upkeep upkeep = new Upkeep(userid,carid,name,pr,introduce,state,begin,update);
		us.addupkeep(upkeep);
	}
}
